<?php
defined( '_VALID_MOS' ) or die( 'Restricted access' );
class HTML_content {	
	//List products
	function showListProduct( &$title, &$total, &$rows, &$pageNav, &$link_page, &$numberPage, &$row ){
	global $mosConfig_live_site, $my;
	$url = $mosConfig_live_site."/administrator/components/com_content/uploads/";
	?>
	<div id="title-cat"><div><?php echo $title;?></div></div>
    <div id="content-cat">
	    <div style="padding:5px; padding-left:0px; padding-right:0px; margin-left:0px; margin-right:5px;">
	    <div class="clear" style="height:10px;"></div>
	        <div>
	        <?php
			if ($total==0){
			?>
			<p style="text-align:center; color:red; line-height:30px;">
			Không tìm thấy sản phẩm nào trong danh mục này !
			</p>
			<?php
			}
			for ($i=0; $i<count($rows); $i++){
			$link = sefRelToAbs("index.php?option=com_content&task=view&catid=".$rows[$i]->catid."&id=".$rows[$i]->id).$rows[$i]->title_alias.".html";
			?>
			<div id="product_cell1">
	            <a href="<?php echo $link;?>">
	            <?php
				if ($rows[$i]->img!=''){
				?>
				<a href="<?php echo $link;?>"><img src="<?php echo $url.$rows[$i]->img;?>" /></a>
				<?php
				}else{
				?>
				<a href="<?php echo $link;?>"><img src="<?php echo $url;?>no_pic.gif" /></a>
				<?php
				}
				?>
	            </a>
	            <div id="productname" class="vtip" title="<?php echo $rows[$i]->title;?>">
	            	<a href="<?php echo $link;?>"><?php echo $rows[$i]->title;?></a>
	            </div>
	        </div>
			<?php
			}
			?>
	        </div>
	    </div>
	    <div class="clear" style="padding:5px;"></div>
	    <div class="clear" style="height:10px;"></div>    
    </div>
    <!-- 
	<script type="text/javascript">
	$(function() {
		<?php 
		for ($i=0; $i<count($rows); $i++){
		?>
		$('#ajax<?php echo $rows[$i]->id;?>').click(function() {
			$('#gio_hang').load('<?php echo $mosConfig_live_site;?>/ajax/orderonline.php?id=<?php echo $rows[$i]->id;?>');
		});
		<?php }?>
	});
	</script>
	 -->
	<?php
		if($total>$numberPage){
			?>
			<div class="page">
			<?php
			echo $pageNav->writePagesLinks( $link_page );
			?>
			</div>
			<?php
		}
	}
	
	//Function Detail Product
	function viewDisplayProduct(&$row, &$total, &$rows, &$pageNav, &$link_page, &$numberPage, &$hangsx, &$totalhangsx, &$linkhangsx ){
	global $mosConfig_live_site, $database;
	$url = $mosConfig_live_site."/administrator/components/com_content/uploads/";
	mysql_query('update jos_content set view='.($row->view+1).' where id='.$row->id);
	?>
		<div id="title-cat"><div>Chi tiết <?php echo $row->title;?></div></div>
    	<div id="content-cat">
    	<div class="view_page">
			<table border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
				<tr>
					<td valign="top" style="padding:3px; padding-right:0; vertical-align:top;">
						<div id="productImageWrapID_<?php echo $row->id;?>">
							<?php
							if ($row->img2!=''){
								echo '<img src="'.$url.$row->img2.'" width="350" border="0" style="float:left; margin:5px 0;" />';
							}else if ($row->img!=''){
								echo '<img src="'.$url.$row->img.'" width="350" border="0" style="float:left; margin:5px 0;" />';
							}else{
								echo '<img src="'.$url.'no_pic.gif" width="350" border="0" style="float:left; margin:5px 0;" />';
							}
							?>
						</div>
						</td>
						<td valign="top" style="padding-left:7px; vertical-align:top;">
						<?php
						if ($row->code!=''){
							echo '<div class="field_detail">';
								echo 'Mã sản phẩm: <b>'.$row->code.'</b>';
							echo '</div>';
						}
						/*
						if ($row->price_niem_yet>0){
							echo '<div class="field_detail_price_ny">';
								echo 'Giá niêm yết: '.number_format($row->price_niem_yet,0,',','.').' VNĐ';
							echo '</div>';
						}
						if ($row->price_giam>0){
							echo '<div class="field_detail_price_ny">';
								echo 'Giá bán: <b style="color:red;">'.number_format($row->price,0,',','.').' VNĐ</b>';
								if($row->don_vi!=''){
									echo ' /<b> '.$row->don_vi.'</b>';
								}
							echo '</div>';
						}else{
							echo '<div class="field_detail">';
								echo 'Giá bán: <b style="color:red;">'.number_format($row->price,0,',','.').' VNĐ</b>';
								if($row->don_vi!=''){
									echo ' /<b> '.$row->don_vi.'</b>';
								}
							echo '</div>';
						}
						*/
						echo '<div class="field_detail">';
							echo 'Số lượt xem: <b>'.number_format($row->view,0,',','.').'</b>';
						echo '</div>';
						echo '<div class="field_detail">';
							echo 'Ngày đưa lên: <b>'.unFormatDate($row->created,"d/m/Y").'</b>';
						echo '</div>';
						echo '<div class="field_detail">';
							echo 'Bao gồm: <b>'.$row->bao_gom.'</b>';
						echo '</div>';
						echo '<div class="field_detail">';
							echo 'Chất liệu: <b>'.$row->chat_lieu.'</b>';
						echo '</div>';
						echo '<div class="field_detail">';
							echo 'Kích thước: <b>'.$row->kich_thuoc.'</b>';
						echo '</div>';
						echo '<div class="field_detail">';
							echo 'Bảo hành: <b>'.$row->bao_hanh.'</b>';
						echo '</div>';
						if ($row->saleoff==1){
							echo '<div class="field_detail" style="background:#B7FFFC; color:red;">';
								echo '<b>Đang khuyến mại</b>';
							echo '</div>';
							if ($row->promotional1!=''){
								echo '<div class="field_detail">';
									echo '[1]. '.$row->promotional1;
								echo '</div>';
							}
							if ($row->promotional2!=''){
								echo '<div class="field_detail">';
									echo '[2]. '.$row->promotional2;
								echo '</div>';
							}
							if ($row->promotional3!=''){
								echo '<div class="field_detail">';
									echo '[3]. '.$row->promotional3;
								echo '</div>';
							}
							if ($row->promotional4!=''){
								echo '<div class="field_detail">';
									echo '[4]. '.$row->promotional4;
								echo '</div>';
							}
							if ($row->promotional5!=''){
								echo '<div class="field_detail">';
									echo '[5]. '.$row->promotional5;
								echo '</div>';
							}
						}
						?>
					</td>
				</tr>
				<!-- 
				<tr>
					<td align="center">
						<?php if ($row->status==1){?>
						<a id="ajax<?php echo $row->id;?>">
							<img src="<?php echo $mosConfig_live_site;?>/templates/maxco/images/cart.jpg" border="0" id="featuredProduct_<?php echo $row->id;?>" />
						</a>
						&nbsp;&nbsp;
						<a href="<?php echo sefRelToAbs("index.php?option=com_orderonline&task=view");?>">
						<img src="<?php echo $mosConfig_live_site;?>/templates/maxco/images/order.gif" border="0" />
						</a>
						<?php }?>
					</td>
					<td></td>
				</tr>
				-->
				<tr><td colspan="2" style="line-height:18px; padding-top:10px;"><?php echo $row->fulltext;?></td></tr>
			</table>
		</div>
		<!-- 
		<script type="text/javascript">
		$(function() {
			$('#ajax<?php echo $row->id;?>').click(function() {
				$('#gio_hang').load('<?php echo $mosConfig_live_site;?>/ajax/orderonline.php?id=<?php echo $row->id;?>');
			});
		});
		</script>
		-->
		<div style="height:10px; padding:5px 0; width:100%;"></div>
		<div class="title_add_title"><div>Các sản phẩm cùng loại khác</div></div>
    	<div style="padding:5px; padding-left:0px; padding-right:0px; margin-left:0px; margin-right:5px;">
	    <div class="clear" style="height:10px;"></div>
	        <div>
	        <?php
			if ($total==0){
			?>
			<p style="text-align:center; color:red; line-height:30px;">
			Không tìm thấy sản phẩm nào trong danh mục này !
			</p>
			<?php
			}
			for ($i=0; $i<count($rows); $i++){
			$link = sefRelToAbs("index.php?option=com_content&task=view&catid=".$rows[$i]->catid."&id=".$rows[$i]->id).$rows[$i]->title_alias.".html";
			?>
			<div id="product_cell1">
	            <a href="<?php echo $link;?>">
	            <?php
				if ($rows[$i]->img!=''){
				?>
				<a href="<?php echo $link;?>"><img src="<?php echo $url.$rows[$i]->img;?>" /></a>
				<?php
				}else{
				?>
				<a href="<?php echo $link;?>"><img src="<?php echo $url;?>no_pic.gif" /></a>
				<?php
				}
				?>
	            </a>
	            <div id="productname" class="vtip" title="<?php echo $rows[$i]->title;?>">
	            	<a href="<?php echo $link;?>"><?php echo $rows[$i]->title;?></a>
	            </div>
	        </div>
			<?php
			}
			?>
	        </div>
	    </div>
	    <div class="clear" style="padding:5px;"></div>
	    <div class="clear" style="height:10px;"></div>
	    <!-- 
		<script type="text/javascript">
		$(function() {
			<?php 
			for ($i=0; $i<count($rows); $i++){
			?>
			$('#ajax<?php echo $rows[$i]->id;?>').click(function() {
				$('#gio_hang').load('<?php echo $mosConfig_live_site;?>/ajax/orderonline.php?id=<?php echo $rows[$i]->id;?>');
			});
			<?php }?>
		});
		</script>
		 -->
		<?php
		if($total>$numberPage){
			?>
			<div class="page">
			<?php
			echo $pageNav->writePagesLinks( $link_page );
			?>
			</div>
			<?php
		}
	}
	
	//showList News
	function showListNews( &$total, &$rows, &$pageNav, &$link_page, &$numberPage, &$row ){
	global $mosConfig_live_site;
	$url = $mosConfig_live_site."/administrator/components/com_content/uploads/";
	?>
	<div id="title-cat"><div><?php echo $row->title;?></div></div>
    <div id="content-cat">
       	<table border="0" width="100%">
 		 	<tbody>
 		 	<tr>
 		 	<?php
			for ($i=0; $i<count($rows); $i++){
			$link = sefRelToAbs("index.php?option=com_content&task=view&catid=".$rows[$i]->catid."&id=".$rows[$i]->id).$rows[$i]->title_alias.".html";
			if (($i+1)%2==0){
				$style = ' class="tdhome"';
			}else{
				$style = ' class="tdhome1"';
			}
			?>
			    <td<?php echo $style;?> style="padding: 10px; position: relative;" align="left" valign="top" width="50%">
				    <div style="position:relative; height:130px;">
					    <div class="servicehomename" style="padding-bottom:10px; text-align:left">
					    <a href="<?php echo $link;?>"><?php echo $rows[$i]->title;?></a>
					    </div>
				      	<a href="<?php echo $link;?>"><img style="margin-right: 5px;" src="<?php echo $url.$rows[$i]->img;?>" class="newsimage" align="left" border="0"></a>
				      	<div class="contexthome" align="justify"><?php echo mb_substr($rows[$i]->introtext,0,200,"utf-8")."...";?></div>
					    <div style="padding-top:3px; width:120px; right:0px; position:absolute; top:110px; " align="left">
					    	<a href="<?php echo $link;?>"><img src="<?php echo $mosConfig_live_site;?>/templates/dogolangchang/images/viewdetail.jpg" style="margin-left: 30px;" border="0" width="76" height="12"></a>
					    </div>
				    </div>
				</td>
			<?php
			if (($i+1)%2==0){
				echo '</tr>';
				echo '<tr>';
			} 
			}
			?>	   
			</tbody>
		</table>
		<?php
		if($total>$numberPage){
			?>
			<div class="page">
			<?php
			echo $pageNav->writePagesLinks( $link_page );
			?>
			</div>
			<?php
		}
		?>
    </div>
	<?php
	}
	
	//Function view News
	function viewDisplayNews( &$row, &$total, &$rows, &$pageNav, &$link_page, &$numberPage ){
	global $mosConfig_live_site, $database;
	$url = $mosConfig_live_site."/administrator/components/com_content/uploads/";
	?>
	<div id="title-cat"><div><?php echo $row->title;?></div></div>
    <div id="content-cat">
    	<?php if ($row->id!=37){?>
    	<div class="view_page">
    		<div class="view_page_img">
			<?php
			if ($row->img2==''){
			?>
			<img src="<?php echo $url.$row->img;?>" border="0" width="150" />
			<?php
			}else{
			?>
			<img src="<?php echo $url.$row->img2;?>" border="0" width="250" />
			<?php
			}
			?>
		</div>	
		<p class="datetime">(<?php echo unFormatDate($row->created,"d/m/Y");?>)</p>
		<p class="description"><?php echo $row->introtext;?></p>
		<?php }?>
		<p style="padding-left: 8px; line-height: 20px;"><?php echo $row->fulltext;?></p>
		</div>
	</div>
	<div class="title_add_title"><div>Các bài viết khác</div></div>
    <div class="content-cat-content">	
		<table border="0" width="100%">
 		 	<tbody>
 		 	<tr>
 		 	<?php
			for ($i=0; $i<count($rows); $i++){
			$link = sefRelToAbs("index.php?option=com_content&task=view&catid=".$rows[$i]->catid."&id=".$rows[$i]->id).$rows[$i]->title_alias.".html";
			if (($i+1)%2==0){
				$style = ' class="tdhome"';
			}else{
				$style = ' class="tdhome1"';
			}
			?>
			    <td<?php echo $style;?> style="padding: 10px; position: relative;" align="left" valign="top" width="50%">
				    <div style="position:relative; height:130px;">
					    <div class="servicehomename" style="padding-bottom:10px; text-align:left">
					    <a href="<?php echo $link;?>"><?php echo $rows[$i]->title;?></a>
					    </div>
				      	<a href="<?php echo $link;?>"><img style="margin-right: 5px;" src="<?php echo $url.$rows[$i]->img;?>" class="newsimage" align="left" border="0"></a>
				      	<div class="contexthome" align="justify"><?php echo mb_substr($rows[$i]->introtext,0,200,"utf-8")."...";?></div>
					    <div style="padding-top:3px; width:120px; right:0px; position:absolute; top:110px; " align="left">
					    	<a href="<?php echo $link;?>"><img src="<?php echo $mosConfig_live_site;?>/templates/dogolangchang/images/viewdetail.jpg" style="margin-left: 30px;" border="0" width="76" height="12"></a>
					    </div>
				    </div>
				</td>
			<?php
			if (($i+1)%2==0){
				echo '</tr>';
				echo '<tr>';
			} 
			}
			?>	   
			</tbody>
		</table>
		<?php
		if($total>$numberPage){
			?>
			<div class="page">
			<?php
			echo $pageNav->writePagesLinks( $link_page );
			?>
			</div>
			<?php
		}
		?>
	</div>	
	<?php
	}

	//Tải báo giá
	function downloadQuotes( &$lsCategories ){
		global $database, $mosConfig_live_site;
		?>
		<div class="title_main"><span>Tải báo giá</span></div>
		<table width="100%" style="margin:0;" cellpadding="0" cellspacing="0" class="border">
			<tr>
				<td align="center" valign="top" bgcolor="#EEEDE9"><b>STT</b></td>
				<td align="center" valign="top" bgcolor="#EEEDE9"><b>NHÓM SẢN PHẨM</b></td>
				<td align="center" valign="top" bgcolor="#EEEDE9"><b>NGÀY CẬP NHẬT</b></td>
				<td align="center" valign="top" bgcolor="#EEEDE9"><b>BÁO GIÁ</b></td>
			</tr>
			<?php 
					for ($i=0; $i<count($lsCategories); $i++){
//						$linkdown = $mosConfig_live_site."/administrator/components/com_categories/uploads/".$lsCategories[$i]->download;
						$linkdown = "index.php?option=com_content&task=save&catid=".$lsCategories[$i]->id;
						$sql = "SELECT * FROM #__categories WHERE section=1 AND published=1 AND parent_id=".$lsCategories[$i]->id." ORDER BY ordering ASC, id DESC";
						$database->setQuery($sql);
						$lsParent = $database->loadOBjectList();
					?>
			<tr>
				<td><b><?php echo $i+1;?></b></td>
				<td><b><?php echo $lsCategories[$i]->title;?></b></td>
				<!--<td><?php echo date("d/m/Y");?></td>-->
				<td><?php echo unFormatDate($lsCategories[$i]->created,"d/m/Y");?></td>
				<?php if ($lsCategories[$i]->download!=''){?>
				<td><a href="<?php echo $linkdown;?>" style="color:#006699; font-weight: normal;">Tải báo giá</a></td>
				<?php }else{?>
				<td align="center"><a href="<?php echo $linkdown;?>" style="color:#006699; font-weight: bold;">Tải báo giá</a></td>
				<?php }?>
			</tr>
			<?php
				for ($j=0; $j<count($lsParent); $j++){
					$linkdown2 = "index.php?option=com_content&task=save&catid=".$lsParent[$j]->id;
					?>
					<tr>
						<td></b></td>
						<td>--- <?php echo $lsParent[$j]->title;?></td>
						<td><?php echo date("d/m/Y");?></td>
						<td><a href="<?php echo $linkdown2;?>" style="color:#006699; font-weight: normal;">Tải báo giá</a></td>
					</tr>
					<?php
				} 
			}
			?>
		</table>
		<?php
	}
}
?>